﻿using System;
using System.Collections;
using System.IO;
using System.Text.Json;
using System.Text.Json.Nodes;
using AutoMapper;
using Chat_IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Caching.Memory;
using NetTaste;

namespace Chat_WebApi.Controllers.v1;

/// <summary>
/// 文件上传
/// </summary>
[Route("/api/v1/[controller]")]
[ApiController]
public class UploadController : BaseController
{
    private readonly ILarUsersService _larUsersService;
    private readonly ILarUsersFriendsService _larUsersFriendsService;
    private readonly IMapper _mapper;
    private readonly ILarTalkListService _larTalkListService;
    private readonly IHubContext<SignalRHub> _hubContext;
    private readonly IMemoryCache _cache;
    private readonly ILarTalkRecordsService _larTalkRecordsService;

    public UploadController(
        IHubContext<SignalRHub> hubClients,
        IMemoryCache memoryCache,
        ILarUsersService larUsersService,
        IMapper mapper,
        ILarTalkListService larTalkListService,
        ILarTalkRecordsService larTalkRecordsService,
        ILarUsersFriendsService larUsersFriendsService
    )
    {
        this._larUsersService = larUsersService;
        this._mapper = mapper;
        this._larTalkListService = larTalkListService;
        this._hubContext = hubClients;
        this._cache = memoryCache;
        this._larTalkRecordsService = larTalkRecordsService;
        this._larUsersFriendsService = larUsersFriendsService;
    }

    /// <summary>
    /// 上传文件
    /// </summary>
    [HttpPost("file-stream")]
    public void MyMethod([FromBody]Object fileStream)
    {
        var a = Request.Body;
    }

    /// <summary>
    /// 保存数据
    /// </summary>
    /// <param name="file"></param>
    /// <param name="id"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    private async void SaveFormAsync(IFormFile file)
    {
        BinaryReader r = new BinaryReader(file.OpenReadStream());
        r.BaseStream.Seek(0, SeekOrigin.Begin); //将文件指针设置到文件开
    }
}